home *** CD-ROM | disk | FTP | other *** search
/ CD-ROM Windows Selection / Windows Selection 1.iso / Programmer's Utilities / Freeman Installer / installr.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-04-10  |  15.1 KB  |  556 lines

  1. #define __INSTALLR_H
  2.  
  3.  
  4. #ifndef __FPATH_H
  5. #include "fpath.h"
  6. #endif
  7. #ifndef __STDIO_H
  8. #include "stdio.h"
  9. #endif
  10. #ifndef __OPRDR_H
  11. #include "oprdr.h"
  12. #endif
  13. #ifndef __STDARG_H
  14. #include "stdarg.h"
  15. #endif
  16. #ifndef __ZIPLDR_H                       /* use dll and indirect calls for zip */
  17. #include "zipldr.h"                      /* so that we don't need those dll if */
  18. #endif                                   /* we don't actually need them. ditto */
  19. #ifndef __UNZLDR_H                       /* for unz                            */
  20. #include "unzldr.h"
  21. #endif
  22. #ifndef __AWNDOBJ_H
  23. #include "awndobj.h"
  24. #endif
  25. #ifndef __VERSION_H
  26. #include "version.h"
  27. #endif
  28.  
  29.  
  30. class dlgprog;
  31. class pmconv;
  32. class simpledde;
  33. class copyctrller;
  34. class copymonitor;
  35.  
  36.  
  37. class installer
  38. {
  39.    int installaux(abspath &srcpath, varpath &dstpath, int isuninstall, copyctrller &cc, copymonitor &cm);
  40.  
  41.    public:
  42.  
  43.    int ecode;                                                    /* error code */
  44.    int isrunpm;                                /* did we start PM to DDE with? */
  45.    int issupressmsg;                         /* should error msg be supressed? */
  46.    HWND owner;                                  /* owner of the error msg dlgs */
  47.    HWND ownerold;                     /* original owner for future restoration */
  48.    pmconv *c;                             /* conversation with program manager */
  49.    simpledde *d;                                                /* dde wrapper */
  50.    oprdrabs *rdr;         /* recorder to record all operations (for uninstall) */
  51.    oprdrabs *rdrold;               /* original recorder for future restoration */
  52.  
  53.    installer();
  54.   ~installer();
  55.  
  56.    int mkdir(abspath &dir);
  57.    int deldir(abspath &dir);
  58.    int delfile(abspath &path);
  59.    int renfile(abspath &oldpath, abspath &newpath);
  60.    int getcddrv();
  61.    int getdrvtype(abspath &root);
  62.    int multimkdir(abspath &dir);
  63.    int multideldir(abspath &dir);
  64.    int multimkdiroffile(abspath &path);
  65.    int multidelfilesindir(abspath &dir);
  66.    int install(abspath &srcpath, abspath &dstpath);
  67.    int install(abspath &srcpath, abspath &dstpath, copymonitor &cm);
  68.    int install(abspath &srcpath, varpath &dstpath, int isuninstall, copyctrller &cc, copymonitor &cm);
  69.    int setfileattrib(abspath &path, DWORD newflags);
  70.    int getfreespace(abspath &root, DWORD *f);
  71.    int getfreespace(abspath &root, double *f);
  72.    int chkfreespace(abspath &root, double minf);
  73.    int begddepm();
  74.    int runpm();
  75.    int endpm();
  76.    int assertinddepm();
  77.    int addgrup(char grup[]);
  78.    int delgrup(char grup[]);
  79.    int additem(char grup[], char item[], char cmdl[], char icon[] = "", int iidx = 0, char dirw[] = "");
  80.    int additem(char grup[], pmiteminfo &pmii);
  81.    int delitem(char grup[], char item[]);
  82.    int chkgrupoccupied(char grup[]);
  83.    int addregkey(int kroot, char kpath[]);
  84.    int delregkey(int kroot, char kpath[]);
  85.    int getregszv(int kroot, char kpath[], char field[], char value[]);
  86.    int setregfield(int kroot, char kpath[], char field[], DWORD vtype, DWORD vsize, BYTE value[]);
  87.    int getnofields(int kroot, char kpath[]);
  88.    int getnosubkeys(int kroot, char kpath[]);
  89.    int chkexistregkey(int kroot, char kpath[]);
  90.    int chkregkeyoccupied(int kroot, char kpath[]);
  91.    int delregfield(int kroot, char kpath[], char field[]);
  92.    int delregfields(int kroot, char kpath[]);
  93.    int delregsubkeys(int kroot, char kpath[]);
  94.    int ini2reg          (abspath &file, char sect[], char entry[], int *kr, char kp[]);
  95.    int delinisect       (abspath &file, char sect[]);
  96.    int addinisect       (abspath &file, char sect[]);
  97.    int addinientry      (abspath &file, char sect[], char entry[], char value[]);
  98.    int delinientry      (abspath &file, char sect[], char entry[], int seqno = 0);
  99.    int insinientry      (abspath &file, char sect[], char entry[], char value[], int seqno = 0);
  100.    int setinivalue      (abspath &file, char sect[], char entry[], char value[], int seqno = 0);
  101.    int setinivaluesimple(abspath &file, char sect[], char entry[], char value[]);
  102.    int installfont(abspath &path, int isuninstall);
  103.    HKEY getregroot(int kroot);
  104.    HWND findpmmainwnd();
  105.    void endddepm(int isendpm);
  106.    void setrdr();
  107.    void setrdr(oprdrabs &rdr);
  108.    void setowner();
  109.    void setowner(HWND owner);
  110.    void error(char msg[], ...);
  111.    void errorvar(char msg[], va_list args);
  112.    void errordel(abspath &path);
  113.    void errorren(abspath &oldpath, abspath &newpath);
  114.    void errormem();
  115.    void erroropen(abspath &path);
  116.    void errorread(abspath &path);
  117.    void errorcopy(abspath &srcpath, abspath &dstpath);
  118.    void errorclose(abspath &path);
  119.    void errormkdir(abspath &dir);
  120.    void errorwrite(abspath &path);
  121.    void errorcreate(abspath &path);
  122.    void errornofile(abspath &path);
  123.    void errorbadpath(abspath &path);
  124.    void erroropenregkey(int kroot, char kpath[]);
  125.    BYTE *getregvalue(int kroot, char kpath[], char field[], DWORD *vtype, DWORD *vsize);
  126.  
  127.    #ifdef WIN32
  128.    char *getdllcountpath();
  129.    DWORD incdllcount(abspath &path);
  130.    DWORD decdllcount(abspath &path);
  131.    DWORD getdllcount(abspath &path);
  132.    DWORD setdllcount(abspath &path, DWORD n);
  133.    #endif
  134.  
  135.    enum                                                          /* error code */
  136.    {
  137.       enul,      egeneric,  edel,      eren,
  138.       emem,      eopen,     eread,     ecopy,
  139.       eclose,    emkdir,    ewrite,    ecreate,
  140.       enofile,   ebadpath
  141.    };
  142.  
  143.    static oprdrnul rdrnul;
  144. };
  145.  
  146. class copymonitor                                              /* copy monitor */
  147. {
  148.    public:
  149.  
  150.    virtual int notifyread(LONG nobytesread) = 0;
  151.    virtual void notifybeg()                 = 0;
  152.    virtual void notifyend()                 = 0;
  153.    virtual UINT getblksize()                = 0;
  154. };
  155.  
  156. class copymonitorprog:public copymonitor     /* copy monitor with progress dlg */
  157. {
  158.    long sofarfile;
  159.    long totalfile;
  160.    double sofar;
  161.    double total;
  162.    dlgprog &d;
  163.  
  164.    public:
  165.  
  166.    copymonitorprog(dlgprog &dx, double totalx):d(dx)
  167.    {
  168.       total = totalx;
  169.       sofar = 0;
  170.       sofarfile = 0;
  171.       totalfile = 0;
  172.    }
  173.    void notifybeg()
  174.    {
  175.       sofarfile = 0;
  176.    }
  177.    void notifyend()
  178.    {
  179.       notifyread(totalfile-sofarfile);   /* in case we skip a part of the file */
  180.    }
  181.    void setsize(long l)
  182.    {
  183.       totalfile = l;
  184.    }
  185.    void undo(long l)
  186.    {
  187.       sofar -= l;
  188.    }
  189.    UINT getblksize()
  190.    {
  191.       return 2048;
  192.    }                
  193.    int notifyread(LONG nobytesread);
  194. };
  195.  
  196. class copymonitorvoid:public copymonitor    /* copy monitor which does nothing */
  197. {
  198.    int *isabort;
  199.  
  200.    public:
  201.  
  202.    copymonitorvoid(int *isabortx = 0)
  203.    {
  204.       isabort = isabortx;
  205.    } 
  206.    int notifyread(LONG nobytesread)
  207.    {
  208.       abswndobj::peekdispatchmsg(1);
  209.  
  210.       return isabort != 0 ? !(*isabort) : 1;
  211.    }
  212.    void notifybeg()
  213.    {
  214.  
  215.    }
  216.    void notifyend()
  217.    {
  218.  
  219.    }
  220.    UINT getblksize()
  221.    {
  222.       return 0;                 /* return 0 means as large a block as possible */
  223.    }
  224. };
  225.  
  226. class cccmp                                        /* how to compare two files */
  227. {
  228.    public:
  229.  
  230.    /* the file (if existed) has been replaced */
  231.    virtual void done()
  232.    {
  233.  
  234.    }
  235.    /* decompress the file first? */
  236.    virtual int chkdecm1st()
  237.    {
  238.       return 0;             /* usually there is no need to decompress it first */
  239.    }
  240.    /* return:0 -- copy   1 -- skip   2 -- error */
  241.    virtual int compare(abspath &srcpath, varpath &dstpath) = 0;
  242. };
  243.  
  244. class cccmpver: public cccmp                   /* version statement comparison */
  245. {
  246.    public:
  247.  
  248.    HWND owner;
  249.  
  250.    /* decomrpess the file first? */
  251.    int chkdecm1st()
  252.    {
  253.       return 1;    /* can't retrieve version statement until it's decompressed */
  254.    }
  255.    /* return:0 -- copy   1 -- skip   2 -- error */
  256.    int compare(abspath &srcpath, varpath &dstpath)
  257.    {
  258.       return version::compare(owner, srcpath, dstpath);
  259.    }
  260. };
  261.  
  262. class cccmpini: public cccmp                         /* ini version comparison */
  263. {
  264.    stcpath dstpath;            /* we'll save version # for this file in done() */
  265.  
  266.    public:
  267.  
  268.    DWORD verhi32;                                  /* high 32 bit of version # */
  269.    DWORD verlo32;                                   /* low 32 bit of version # */
  270.    stcpath inipath;                                    /* path to the INI file */
  271.  
  272.    int compare(abspath &srcpath, varpath &dstpath);
  273.  
  274.    void done();
  275. };
  276.  
  277. class cccmptime: public cccmp                         /* time stamp comparison */
  278. {
  279.    public:
  280.  
  281.    int compare(abspath &srcpath, varpath &dstpath);
  282. };
  283.  
  284. class cccmpsz: public cccmp                            /* file size comparison */
  285. {
  286.    public:
  287.  
  288.    long srcl;
  289.  
  290.    int compare(abspath &srcpath, varpath &dstpath);
  291. };
  292.  
  293. class cccmpnone: public cccmp                          /* no comparison at all */
  294. {
  295.    public:
  296.  
  297.    /* return:0 -- copy   1 -- skip   2 -- error */
  298.    int compare(abspath &/*srcpath*/, varpath &/*dstpath*/)
  299.    {
  300.       return 0;
  301.    }
  302. };
  303.  
  304.  
  305. class ccread                                        /* how to read source file */
  306. {
  307.    public:
  308.  
  309.    /* return:true -- ok   false -- error */
  310.    virtual int opensrc(abspath &srcpath) = 0;
  311.  
  312.    /* return:true -- ok   false -- error */
  313.    virtual int closesrc()                = 0;
  314.  
  315.    /* return:no of bytes read -- ok   -1 -- fail */
  316.    virtual UINT getsrc(char b[], UINT n) = 0;
  317. };
  318.  
  319. class ccrdnorm: public ccread                              /* read normal file */
  320. {
  321.    HFILE h;
  322.  
  323.    public:
  324.  
  325.    /* return:true -- ok   false -- error */
  326.    int opensrc(abspath &srcpath)
  327.    {
  328.       OFSTRUCT ofs;
  329.  
  330.       return (h = OpenFile(srcpath, &ofs, OF_READ)) != -1;
  331.    }
  332.    /* return:true -- ok   false -- error */
  333.    int closesrc()
  334.    {
  335.       return _lclose(h) != -1;
  336.    }
  337.    /* return:no of bytes read -- ok   -1 -- fail */
  338.    UINT getsrc(char b[], UINT n)
  339.    {
  340.       return _lread(h, b, n);
  341.    }
  342. };
  343.  
  344. class ccrdcomp: public ccread                          /* read compressed file */
  345. {
  346.    int isopen;                                        /* did we open the file? */
  347.  
  348.    lzpunzldr ul;                                    /* used to load lzpunz.dll */
  349.  
  350.    public:
  351.  
  352.    /* return:no of bytes read -- ok   -1 -- fail */
  353.    UINT getsrc(char b[], UINT n)
  354.    {
  355.       return ul.LzpUnzRead(b, n);
  356.    }
  357.    int opensrc(abspath &srcpath);
  358.    int closesrc();
  359. };
  360.  
  361. class ccwrite                                        /* how to write to a file */
  362. {
  363.    public:
  364.  
  365.    /* return:true -- ok   false -- error */
  366.    virtual int opendst(abspath &dstpath) = 0;
  367.  
  368.    /* return:true -- ok   false -- error */
  369.    virtual int closedst()                = 0;
  370.  
  371.    /* return:true -- appending   false -- creating */
  372.    virtual int chkappend()
  373.    {
  374.       return 0;                         /* usually we create instead of append */
  375.    }
  376.    /* return:no of bytes written -- ok   -1 -- fail */
  377.    virtual UINT putdst(char b[], UINT n) = 0;
  378.  
  379.    /* log down the changes */
  380.    virtual void record(oprdrabs &rdr, abspath &srcpath, abspath &dstpath, int isuninstall) = 0;
  381. };
  382.  
  383. class ccwrnorm: public ccwrite                       /* write to a normal file */
  384. {
  385.    HFILE h;
  386.  
  387.    public:
  388.  
  389.    /* return:true -- ok   false -- error */
  390.    int opendst(abspath &dstpath)
  391.    {
  392.       OFSTRUCT ofs;
  393.  
  394.       return (h = OpenFile(dstpath, &ofs, OF_CREATE)) != -1;
  395.    }
  396.    /* return:true -- ok   false -- error */
  397.    int closedst()
  398.    {
  399.       return _lclose(h) != -1;
  400.    }
  401.    /* return:no of bytes written -- ok   -1 -- fail */
  402.    UINT putdst(char b[], UINT n)
  403.    {
  404.       return _lwrite(h, b, n);
  405.    }
  406.    void record(oprdrabs &rdr, abspath &srcpath, abspath &dstpath, int isuninstall)
  407.    {
  408.       rdr.instcreatefile(srcpath, dstpath, isuninstall);
  409.    }
  410. };
  411.  
  412. class ccwrnormapp: public ccwrite                   /* append to a normal file */
  413. {
  414.    int isappend;                 /* did the file exist when we appended to it? */
  415.    HFILE h;
  416.    DWORD l;                                       /* size of the original file */
  417.  
  418.    public:
  419.  
  420.    /* return:true -- ok   false -- error */
  421.    int closedst()
  422.    {
  423.       return _lclose(h) != -1;
  424.    }
  425.    /* return:true -- appending   false -- creating */
  426.    int chkappend()
  427.    {
  428.       return 1;
  429.    }
  430.    /* return:no of bytes written -- ok   -1 -- fail */
  431.    UINT putdst(char b[], UINT n)
  432.    {
  433.       return _lwrite(h, b, n);
  434.    }
  435.    int opendst(abspath &dstpath);
  436.  
  437.    void record(oprdrabs &rdr, abspath &srcpath, abspath &dstpath, int isuninstall);
  438. };
  439.  
  440. class ccwrcomp: public ccwrite                   /* write to a compressed file */
  441. {
  442.    int iscreated;
  443.  
  444.    lzpzipldr zl;                                    /* used to load lzpzip.dll */
  445.  
  446.    public:
  447.  
  448.    /* return:true -- ok   false -- error */
  449.    void record(oprdrabs &rdr, abspath &srcpath, abspath &dstpath, int isuninstall)
  450.    {
  451.       rdr.instcreatefile(srcpath, dstpath, isuninstall);
  452.    }
  453.    /* return:no of bytes written -- ok   -1 -- fail */
  454.    UINT putdst(char b[], UINT n)
  455.    {
  456.       return zl.LzpZipWrite(b, n);
  457.    }
  458.    int opendst(abspath &dstpath);
  459.    int closedst();
  460. };
  461.  
  462. class copyctrller
  463. {
  464.    public:
  465.  
  466.    int issametime;                                         /* keep time stamp? */
  467.    cccmp *cmp;                                 /* how to compare the two files */
  468.    ccread *rd;                                  /* how to read the source file */
  469.    ccwrite *wr;                                /* how to write the target file */
  470.  
  471.    copyctrller()
  472.    {
  473.       issametime = 0;                     /* no, just use the time of creation */
  474.       cmp = 0;
  475.       rd = 0;
  476.       wr = 0;
  477.    }
  478.    int chkdecm1st()
  479.    {
  480.       return cmp->chkdecm1st();
  481.    }
  482.    int chkappend()
  483.    {
  484.       return wr->chkappend();
  485.    }
  486.    /* return:0 -- copy   1 -- skip   2 -- error */
  487.    int compare(abspath &srcpath, varpath &dstpath)
  488.    {
  489.       return cmp->compare(srcpath, dstpath);
  490.    }
  491.    /* return:true -- ok   false -- error */
  492.    int opensrc(abspath &srcpath)
  493.    {
  494.       return rd->opensrc(srcpath);
  495.    }
  496.    /* return:true -- ok   false -- error */
  497.    int opendst(abspath &dstpath)
  498.    {
  499.       return wr->opendst(dstpath);
  500.    }
  501.    /* return:true -- ok   false -- error */
  502.    int closesrc()
  503.    {
  504.       return rd->closesrc();
  505.    }
  506.    /* return:true -- ok   false -- error */
  507.    int closedst()
  508.    {
  509.       return wr->closedst();
  510.    }
  511.    /* return:no of bytes read -- ok   -1 -- fail */
  512.    UINT getsrc(char b[], UINT n)
  513.    {
  514.       return rd->getsrc(b, n);
  515.    }
  516.    /* return:no of bytes written -- ok   -1 -- fail */
  517.    UINT putdst(char b[], UINT n)
  518.    {
  519.       return wr->putdst(b, n);
  520.    }
  521.    void done()
  522.    {
  523.       cmp->done();
  524.    }
  525.    void record(oprdrabs &rdr, abspath &srcpath, abspath &dstpath, int isuninstall)
  526.    {
  527.       wr->record(rdr, srcpath, dstpath, isuninstall);
  528.    }
  529. };
  530.  
  531. class pmddekeeper
  532. {
  533.    int isendpm;
  534.  
  535.    installer &ir;
  536.  
  537.    public:
  538.  
  539.    pmddekeeper(installer &ir_):ir(ir_)
  540.    {
  541.       isendpm = 1;
  542.  
  543.       ir.begddepm();
  544.    }
  545.    pmddekeeper(int *r, installer &ir_, int isendpm_):ir(ir_)
  546.    {
  547.       isendpm = isendpm_;
  548.  
  549.       *r = ir.begddepm();                                         /* begin DDE */
  550.    }
  551.   ~pmddekeeper()
  552.    {
  553.       ir.endddepm(isendpm);
  554.    }
  555. };
  556.